package com.geccocrawler.gecco.spider.render;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;

/**
 * 注入某个属性异常
 *
 * @author huchengyi
 */
public class FieldRenderException extends Exception {

    private static Logger log = LoggerFactory.getLogger(FieldRenderException.class);

    private static final long serialVersionUID = 5698150653455275921L;

    private Field field;

    public FieldRenderException(Field field, String message) {
        super(message);
        this.field = field;
    }

    public FieldRenderException(Field field, String message, Throwable cause) {
        super(message, cause);
        this.field = field;
    }

    public Field getField() {
        return field;
    }

    public void setField(Field field) {
        this.field = field;
    }

    public static void log(Field field, String message, Throwable cause) {
        log.error(field.getName() + " render error : " + message);
        if (cause != null) {
            log.error(message, cause);
        }
    }

    public static void log(Field field, String message) {
        log(field, message, null);
    }
}
